package ecom.nopecom.steps.account;

import consumer.CheckOut;
import consumer.HomePage;
import consumer.ProductPage;
import consumer.ShoppingCartPage;
import cucumber.annotation.After;
import cucumber.annotation.Before;
import ecom.nopecom.account.Registration;
//import ecom.nopecom.other.HomePage;
import ecom.nopecom.util.NopComFactory;
import org.junit.Assert;

import cucumber.annotation.Before;
import cucumber.annotation.en.Given;
import cucumber.annotation.en.Then;
import cucumber.annotation.en.When;
import cucumber.runtime.PendingException;
import ecom.nopecom.account.Login;
import ecom.nopecom.util.Consumer;
import ecom.nopecom.util.ConsumerProvider;
import org.junit.BeforeClass;

public class AccountStepDefs {
	
	Login loginPage = new Login();
	ConsumerProvider consumerProvider = new ConsumerProvider();
    Registration registration = new Registration();
    CheckOut checkOut = new CheckOut();
    ShoppingCartPage shoppingCartPage = new ShoppingCartPage();

    @Before
   public void loadDetails()
    {
       NopComFactory.getBrowser();
    }

	
	@Given("^User is in Login Page$")
	public void User_is_in_Login_Page() {
	 loginPage.goToLoginPage();
	}

	@When("^User tries to Login with (.+) and (.+)$")
	public void User_tries_to_Login(String username,String password) {
	    // Express the Regexp above with the code you wish you had
		Consumer consumer = consumerProvider.registerUser(username, password, "First");
		 loginPage.login(consumer);
	}

	@Then("^User successfully logs in$")
	public void logs_in() {
	
		Consumer consumer = ConsumerProvider.getConsumer();
		if(consumer.getUserLoggedInStatus())
		{

		}
		else
		{
			Assert.fail("User not loggeed in");
		}
	}

	@Then("^see a welcome message with (.+)$")
	public void see_a_welcome_message(String firstname) {
	//	if(loginPage.getWelcomeMessage().equalsIgnoreCase(firstname))
		{
			    Assert.fail("No welcome message "+firstname);
		}
	}
	
	@After
	public void tearDown()
	{
		if(NopComFactory.getBrowser()!=null)
		{
			NopComFactory.getBrowser().quit();
			NopComFactory.mBrowser=null;
			
		}



	}
    @Given("^user is registered$")
    public void user_is_registered() {
        loginPage.goToRegistrationPage();

        Consumer consumer = ConsumerProvider.getConsumer();
        registration.register(consumer);
    }

    @Given("^Limit for the hotel is set for max rooms$")
    public void Limit_for_the_hotel_is_set_for_max_rooms() {
      System.out.print("yes the Limit for the hotel is set for max rooms is set");
//        loginPage.goToLoginPage();
    }

    @When("^CM try to exceed the room limt$")
    public void CM_try_to_exceed_the_room_limt() {
        // Express the Regexp above with the code you wish you had
        System.out.print("yes the CM try to exceed the room limt");
//        throw new PendingException();
    }

    @Then("^Error message should be shown$")
    public void Error_message_should_be_shown() {
        System.out.print("yes the Error message should be shown");
    }

    @Then("^Message should say 'Max Limit Reached'$")
    public void Message_should_say_Max_Limit_Reached() {
        Assert.fail();
        System.out.print("yes the Message should say 'Max Limit Reached'");
    }
    
    
    //--------------------------------------------------------------------------///
    @Given("^consumer logs into application$")
    public void loginAndRegister() {
    	loginPage.goToLoginPage();
      registration.register(ConsumerProvider.getConsumer());
    }

    @Given("^consume have '(.+)' item in basket$")
    public void consume_have_single_item_in_basket(String value) {
        HomePage h = new HomePage();
                             h.gotoHomepage();
    	if(value=="single")
    	{
    		h.addDefaultItem();
            ProductPage productPage = new ProductPage();
            productPage.additemtobasket();
    	}
    	else
    	{
            h.addDefaultItem();
            ProductPage productPage = new ProductPage();
            productPage.additemtobasket();
            h.gotoHomepage();h.addSecondDefaultItem();
            productPage.additemtobasket();

    	}

    }

    @When("^consumer checkouts with no discount$")
    public void consumer_checkouts_with_no_discount() {
        // Express the Regexp above with the code you wish you had
        ProductPage productPage = new ProductPage();
        productPage.gotoshoppingcart();

        shoppingCartPage.gotocheckout();
//        CheckOut checkOut = new CheckOut();
//        checkOut.confirmShippingAddress();


    }

    @Then("^can see payment page$")
    public void can_see_payment_page() {
        // Express the Regexp above with the code you wish you had

        checkOut.fillAddressForm();
        checkOut.confirmShippingAddress();
        checkOut.confirmShippingMethod();
        Assert.assertTrue(checkOut.isPaymentScreenDisplayed());
    }

    @Then("^price should be as per total$")
    public void price_should_be_as_per_total() {
        checkOut.checkPrice(shoppingCartPage.getPrice());

    }

    @Then("^consumer have option of credit card or debit card$")
    public void consumer_have_option_of_credit_card_or_debit_card() {
        checkOut.confirmPaymentWithMethod("CREDITCARD");
        // Express the Regexp above with the code you wish you had
//        throw new PendingException();
    }

//    @Given("^consume have 'Multipe' item in basket$")
//    public void consume_have_Multipe_item_in_basket() {
//        // Express the Regexp above with the code you wish you had
//        throw new PendingException();
//    }

    @When("^consumer checkouts with discount$")
    public void consumer_checkouts_with_discount() {
        // Express the Regexp above with the code you wish you had
//        throw new PendingException();
    }
    
    @Given("^User is already registered$")
    public void User_is_already_registered() {
        // Express the Regexp above with the code you wish you had
       // throw new PendingException();
    	
    }

    @When("^he tries to register$")
    public void he_tries_to_register() {
        // Express the Regexp above with the code you wish you had
       // throw new PendingException();
    }

    @Then("^an error message should be displayed$")
    public void an_error_message_should_be_displayed() {
        // Express the Regexp above with the code you wish you had
     //   throw new PendingException();
    }
}